import { createVNode, render } from 'vue'
import FormDialog from './FormDialog.vue'
import { ref } from 'vue'
import { FormDialogOptionInterface } from './FormDialog.dto'

const div = document.createElement('div')
export function openFormDialog(option: FormDialogOptionInterface) {
  const show = ref(true)
  const instance = createVNode(FormDialog, {
    show,
    title: option.title,
    form: option.form,
    onSubmit: option.onSubmit
  })

  document.body.append(div)
  render(instance, div)
  return {
    close() {
      if (instance.component) {
        instance.component.props.show = false
      }
    }
  }
}
